package com.situ.javase.day11;

import java.awt.GridLayout;

import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class GridLayoutDemo {

	public static void main(String[] args) {
		JFrame frame = new JFrame();
		JPanel panel = new JPanel();
		frame.add(panel);
		// 设置布局
		panel.setLayout(new GridLayout(3, 3));
		// 创建控件
		JButton[] buttons = new JButton[9];
		for (int i = 0; i < buttons.length; i++) {
			JButton button = new JButton((i + 1) + "");
			buttons[i] = button;
		}
		// 添加组件
		for (int i = 0; i < buttons.length; i++) {
			panel.add(buttons[i]);
		}
		
		// 设置大小，单位是像素
		// width the new width of this component in pixels
		frame.setSize(500, 400);
		// 设置初始位置
		frame.setLocation(500, 200);
		// 默认是不显示
		frame.setVisible(true);
		// 关闭Frame
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}
